Show a better error message when using custom verbs.

Darren Cauthon 9 years ago
parent
commit
65ff919c29
3 changed files with 12 additions and 1 deletions
  1. 3 0
      Gemfile.lock
  2. 1 1
      app/models/agents/webhook_agent.rb
  3. 8 0
      spec/models/agents/webhook_agent_spec.rb

+ 3 - 0
Gemfile.lock

@@ -609,3 +609,6 @@ DEPENDENCIES
609 609
   weibo_2!
610 610
   wunderground (~> 1.2.0)
611 611
   xmpp4r (~> 0.5.6)
612
+
613
+BUNDLED WITH
614
+   1.10.6

+ 1 - 1
app/models/agents/webhook_agent.rb

@@ -46,7 +46,7 @@ module Agents
46 46
       return ["Not Authorized", 401] unless secret == interpolated['secret']
47 47
 
48 48
       #check the verbs
49
-      verbs = (interpolated['verbs'] || 'post').split(/,/).map { |x| x.strip.downcase }
49
+      verbs = (interpolated['verbs'] || 'post').split(/,/).map { |x| x.strip.downcase }.select { |x| x.present? }
50 50
       return ["Please use #{verbs.join('/').upcase} requests only", 401] unless verbs.include?(method)
51 51
 
52 52
       [payload_for(params)].flatten.each do |payload|

+ 8 - 0
spec/models/agents/webhook_agent_spec.rb

@@ -192,6 +192,14 @@ describe Agents::WebhookAgent do
192 192
           expect(out).to eq(['Event Created', 201])
193 193
         end
194 194
 
195
+        it "should not accept DELETE" do
196
+          out = nil
197
+          expect {
198
+            out = agent.receive_web_request({ 'secret' => 'foobar', 'some_key' => payload }, "delete", "text/html")
199
+          }.to change { Event.count }.by(0)
200
+          expect(out).to eq(['Please use PUT/POST/GET requests only', 401])
201
+        end
202
+
195 203
       end
196 204
 
197 205
     end